<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');

/**
 * TYPOlight webCMS
 * Copyright (C) 2005 Leo Feyer
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program. If not, please visit the Free
 * Software Foundation website at http://www.gnu.org/licenses/.
 *
 * PHP version 5
 * @copyright  Softleister 2008 
 * @author     Softleister <info@softleister.de> 
 * @package    Ticker 
 * @license    LGPL 
 * @filesource
 */


class ModuleTickerFE extends Frontend
{
  /**
   * Zusätzliche InsertTags für Tickermodul
   * {‎{ticker::next_event::ID}}    nächsten Event aus dem Kalender mit der ID
   */
  public function TickerInsertTags( $strTag )
  {
    $this->Date = new Date(date('Ymd'),'Ymd');
    $heute = $this->Date->dayBegin;		// Tagesbeginn HEUTE

    $arrTag = split( '::', $strTag );
		
    if( $arrTag[0] !== 'ticker' )
      return false;

    if( ($arrTag[1] === 'next_event') && is_numeric($arrTag[2]) && ($arrTag[2]>0) ) {
      // Get events of the current period
      $objEvent = $this->Database->prepare( "SELECT * FROM tl_calendar_events WHERE pid=? AND published='1' AND startDate>=? ORDER BY startDate" )
                                 ->limit( 1 )
				 ->execute( $arrTag[2], $heute );

      if( $objEvent->numRows == 0 )
        return false;

      if( trim($objEvent->teaser) == '' ) return date($GLOBALS['TL_CONFIG']['dateFormat'], $objEvent->startDate) . ' ' . $objEvent->title;   // Notlösung, wenn kein Teaser angegeben
      else return date($GLOBALS['TL_CONFIG']['dateFormat'], $objEvent->startDate) . ' ' . $objEvent->teaser;
    }
    return false;
  }
}	

?>